package com.youdoneed.user.job;

import com.youdoneed.base.application.ResultMessage;
import com.youdoneed.base.pagination.Page;
import com.youdoneed.base.pagination.Paging;
import com.youdoneed.user.model.Job;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 职业请求控制器。
 *
 * @author Ewing
 * @date 2017.2.8
 */
@RestController
@RequestMapping("/job")
@Api(description = "职业")
public class JobController {

    @Autowired
    private JobService jobService;

    /**
     * 新增职业。
     */
    @RequestMapping(value = "/addJob", method = {RequestMethod.GET, RequestMethod.POST})
    @ApiOperation("新增职业")
    @ApiImplicitParams(@ApiImplicitParam(name = "name", value = "名称", required = true, paramType = "query"))
    public ResultMessage addJob(Job job) {
        jobService.addJob(job);
        return new ResultMessage();
    }

    /**
     * 根据ID获取职业。
     */
    @ApiOperation("根据ID获取职业")
    @ApiImplicitParams(@ApiImplicitParam(name = "jobId", value = "职业ID", required = true, paramType = "query"))
    @RequestMapping(value = "/getJob", method = {RequestMethod.GET, RequestMethod.POST})
    public ResultMessage<Job> getJob(String jobId) {
        return new ResultMessage<>(jobService.getJob(jobId));
    }

    /**
     * 修改职业。
     */
    @RequestMapping(value = "/updateJob", method = {RequestMethod.GET, RequestMethod.POST})
    @ApiOperation("修改职业")
    @ApiImplicitParams({@ApiImplicitParam(name = "jobId", value = "职业ID", required = true, paramType = "query")})
    public ResultMessage updateJob(Job job) {
        jobService.updateJob(job);
        return new ResultMessage();
    }

    /**
     * 删除职业。
     */
    @ApiOperation("删除职业")
    @ApiImplicitParams(@ApiImplicitParam(name = "jobId", value = "职业ID", required = true, paramType = "query"))
    @RequestMapping(value = "/deleteJob", method = {RequestMethod.GET, RequestMethod.POST})
    public ResultMessage deleteJob(String jobId) {
        jobService.deleteJob(jobId);
        return new ResultMessage();
    }

    /**
     * 根据条件查询职业。
     */
    @ApiOperation("根据条件查询职业")
    @RequestMapping(value = "/findJobs", method = {RequestMethod.GET, RequestMethod.POST})
    public ResultMessage<Page<Job>> findJobs(Paging paging, String name) {
        Page<Job> jobs = jobService.findJobs(paging, name);
        return new ResultMessage<>(jobs);
    }

    /**
     * 向上移动顺序。
     */
    @ApiOperation("向上移动顺序")
    @RequestMapping(value = "/sortMoveUp", method = {RequestMethod.GET, RequestMethod.POST})
    public ResultMessage sortMoveUp(String jobId) {
        jobService.sortMoveUp(jobId);
        return new ResultMessage();
    }

    /**
     * 向下移动顺序。
     */
    @ApiOperation("向下移动顺序")
    @RequestMapping(value = "/sortMoveDown", method = {RequestMethod.GET, RequestMethod.POST})
    public ResultMessage sortMoveDown(String jobId) {
        jobService.sortMoveDown(jobId);
        return new ResultMessage();
    }

    /**
     * 获取显示的职业。
     */
    @ApiOperation("获取显示的职业")
    @RequestMapping(value = "/showJobs", method = {RequestMethod.GET, RequestMethod.POST})
    public ResultMessage<List<Job>> showJobs() {
        List<Job> jobs = jobService.showJobs();
        return new ResultMessage<>(jobs);
    }

}
